package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.User;
import com.cskaoyan.bean.comment.*;
import com.cskaoyan.service.WXCommentService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: heliming
 * @date: 2021/6/7
 * @description:
 */
@RestController
@RequestMapping("wx/comment")
public class WXCommentController {

    @Autowired
    WXCommentService wxCommentService;

    @GetMapping("list")
    public BaseRespVo list(Integer valueId, Byte type, Integer size, Integer page, Integer showType) {
        WXCommentList wxCommentList = wxCommentService.selectList(valueId, type, size, page, showType);
        return BaseRespVo.ok(wxCommentList);
    }

    @GetMapping("count")
    public BaseRespVo count(Integer valueId, Integer type) {
        WXCommentCount wxCommentCount = wxCommentService.selectCount(valueId,type);
        return BaseRespVo.ok(wxCommentCount);
    }

    @PostMapping("post")
    public BaseRespVo post(@RequestBody WXCommentPostBO wxCommentPostBO) {
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getPrincipal();
        Integer userId = user.getId();
       WXCommentPostVO wxCommentPostVO =  wxCommentService.insertPost(wxCommentPostBO,userId);
        return BaseRespVo.ok(wxCommentPostVO);
    }

}
